package secretaryGUI;

import guiCode.secretaryScreenCode;

import java.awt.Component;
import java.sql.SQLException;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableCellRenderer;

public class secretaryAlerts {

	public void showMessages(createSecretaryWindow csw, secretaryScreenCode ssc,JFrame secretaryScreen,String msg, String title, int type) {
		if (type == 1) {
			JOptionPane.showMessageDialog(secretaryScreen, msg, title,
					JOptionPane.ERROR_MESSAGE);
		}
		if (type == 2) {// open next new semester
			int option = JOptionPane.showConfirmDialog(secretaryScreen, msg,
					title, JOptionPane.YES_NO_OPTION,
					JOptionPane.QUESTION_MESSAGE);
			if (option == JOptionPane.YES_OPTION) {
				ssc.openNewSemester(csw.calendar.setPickedDate(),
						ssc.getSemesterForEdit());
			}
		}
		if (type == 3) { // open current new semester
			int option = JOptionPane.showConfirmDialog(secretaryScreen, msg,
					title, JOptionPane.YES_NO_OPTION,
					JOptionPane.QUESTION_MESSAGE);
			if (option == JOptionPane.YES_OPTION) {
				ssc.openNewSemester(csw.calendar.setPickedDate(),
						ssc.getSemesterForEdit());
			}
		}
		if (type == 4) {
			JOptionPane.showMessageDialog(secretaryScreen, msg, title,
					JOptionPane.INFORMATION_MESSAGE);
		}
		if (type == 5) {
			String str = JOptionPane.showInputDialog(null,
					"Enter new class name : ", "Changing class name", 1);
			int checkResult;
			if ((checkResult = ssc.checkClassRegex(str)) == 1) {
				ssc.changeClassName(csw, ssc, secretaryScreen,16, 0, str,
						(String) csw.table.getValueAt(csw.row, csw.col - 2),
						(String) csw.table.getValueAt(csw.row, csw.col - 1));
				try {
					csw.table.setModel(ssc.getClasses(ssc.getSemesterForEdit()));
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
				centerRenderer.setHorizontalAlignment(JLabel.CENTER);
				for (int i = 0; i < csw.table.getColumnCount(); i++)
					csw.table.getColumnModel().getColumn(i)
							.setCellRenderer(centerRenderer);
			} else {
				if (checkResult == 0) {
					showMessages(
							csw, ssc, secretaryScreen, "Class name must be of type [1-12][A-Z]\nFor example: 1A, 9C, ...",
							"Class editor - failure", 1);
				}

			}

		}

	}
}
